<template>
	<van-nav-bar title="消费记录" left-text="" left-arrow @click-left="goBack" />
	<van-pull-refresh v-model="refreshing" @refresh="onRefresh">
		<van-list
			v-model:loading="loading"
			:finished="finished"
			finished-text="没有更多了"
			@load="onLoad"
		>
			<van-cell
				label-class="label_color"
				:title="item.content"
				:value="item.createtime"
				v-for="item in list"
			/>
		</van-list>
	</van-pull-refresh>
</template>
<script setup>
	const router = useRouter();
	const list = ref([]);
	const loading = ref(false);
	const finished = ref(false);
	let { cookies } = useCookies();
	let LoginUser = reactive(cookies.get("LoginUser"));
	const refreshing = ref(false);
	let num = 1;
	// 返回
	const goBack = () => {
		router.push("/business/index");
	};

	const onLoad = async () => {
		const result = await Api.business.record({ busid: LoginUser.id, num: num });
		if (result.code == 0) {
			finished.value = true;
		}
		if (result.code == 1) {
			list.value.push(...result.data.record);
			loading.value = false;
			num++;
		}
		refreshing.value = false;
		// 数据全部加载完成
		if (list.value.length >= result.data.count) {
			finished.value = true;
			loading.value = false;
		}
	};
	const onRefresh = () => {
		num = 1;
        list.value = [];
		// 清空列表数据
		finished.value = false;

		// 重新加载数据
		// 将 loading 设置为 true，表示处于加载状态
		loading.value = true;
		onLoad();
	};
</script>

<style scoped lang="scss">
	.van-list {
		.van-cell {
			::v-deep .van-cell__value {
				display: flex;
				align-items: center;
				justify-content: flex-end;
			}
		}
	}
</style>